(*
	HMSToTicks() -- Convert from HMS format to 1/60ths of a second

	To compile and link this file using Macintosh Programmer's Workshop,

		pascal -w HMSToTicks.p

		link -m ENTRYPOINT -o HyperCommands -rt XFCN=8000 -sn Main=HMSToTicks ¶
			HMSToTicks.p.o "{MPW}"PLibraries:PasLib.o

	Copyright © 1988 Apple Computer, Inc.

	2/88 - Initial coding by Harry R. Chesley.
*)

{$R-}

{$S HMSToTicks } 	{ Segment name must be the same as the command name. }

unit DummyUnit;

interface

uses MemTypes, QuickDraw, OSIntf, ToolIntf, HyperXCmd;

procedure EntryPoint(paramPtr: XCmdPtr);
	
implementation

type

Str31 = String[31];

procedure HMSToTicks(paramPtr: XCmdPtr); forward;

procedure EntryPoint(paramPtr: XCmdPtr);

	begin
		HMSToTicks(paramPtr);
	end;

procedure HMSToTicks(paramPtr: XCmdPtr);

	var str: Str255;
		i: integer;

	{$I XCmdGlue.inc}

	procedure Fail(errMsg: Str255); { set theResult and quit }
		begin
			paramPtr^.returnValue := PasToZero(errMsg);
			exit(HMSToTicks);
		end;

	{$I VideoUtil.inc}

	function pairAt(index: integer): longInt;
		{ Return a number which corresponds to the two digit value at str[index] and str[index+1]. }

		begin
			pairAt := 10*(ord4(str[index])-ord4('0'))+(ord4(str[index+1])-ord4('0'));
		end;

	begin
		if paramPtr^.paramCount <> 1 then Fail('parameter count is not 1');

		{ Get the HMS form, and make sure it's the right length. }
		GetStrParm(1,str);
		if length(str) > 6 then str := Copy(str,length(str)-5,6);
		for i := length(str) to 5 do str := Concat('0',str);

		{ Calculate the ticks form. }
		paramPtr^.returnValue := PasToZero(LongToStr(60*(pairAt(5)+60*(pairAt(3)+60*pairAt(1)))));
	end;

end.
